package horse;

public class horse {

	int level;
	int stor;
	int count = 0;
	int horse(int w, int h, int[][] mass, int level)
	{
		//проверка ходов
		mass[w][h] = level;
		int flag = 1; 
		if (level == stor*stor ) {count = count+1; printArr(mass, stor, stor);}
		if((0 <= h+2) && (h+2 < stor) && (0 <= w+1) && (w+1 < stor) && (mass[w+1][h+2] == 0)) {flag = horse(w+1, h+2, mass, level+1);}
		if((0 <= h+1) && (h+1 < stor) && (0 <= w+2) && (w+2 < stor) && (mass[w+2][h+1] == 0)) {flag = horse(w+2, h+1, mass, level+1);}
		if((0 <= h-2) && (h-2 < stor) && (0 <= w-1) && (w-1 < stor) && (mass[w-1][h-2] == 0)) {flag = horse(w-1, h-2, mass, level+1);}
		if((0 <= h-1) && (h-1 < stor) && (0 <= w-2) && (w-2 < stor) && (mass[w-2][h-1] == 0)) {flag = horse(w-2, h-1, mass, level+1);}
		if((0 <= h+2) && (h+2 < stor) && (0 <= w-1) && (w-1 < stor) && (mass[w-1][h+2] == 0)) {flag = horse(w-1, h+2, mass, level+1);}
		if((0 <= h+1) && (h+1 < stor) && (0 <= w-2) && (w-2 < stor) && (mass[w-2][h+1] == 0)) {flag = horse(w-2, h+1, mass, level+1);}
		if((0 <= h-2) && (h-2 < stor) && (0 <= w+1) && (w+1 < stor) && (mass[w+1][h-2] == 0)) {flag = horse(w+1, h-2, mass, level+1);}
		if((0 <= h-1) && (h-1 < stor) && (0 <= w+2) && (w+2 < stor) && (mass[w+2][h-1] == 0)) {flag = horse(w+2, h-1, mass, level+1);}

		if (flag == 1)  { mass[w][h] = 0; return 1;} 

		return 0;
	}
	public static void printArr(int arr[][], int a, int b)
		{
		for(int k = 0; k < a; k++)
		{
			for(int l = 0; l < b; l++)
				System.out.print(arr[k][l] + "\t");
		
			System.out.println();
		}
		System.out.println();
	}
}


